#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 1e4+10;

int n,k;
int tr[N][510],h[N],mx,ans;

void add(int x,int y,int val){
	y++;
	for(;x <= mx + k;x += x & -x)
		for(int i = y;i <= k + 1;i += i & -i)
			tr[x][i] = max(tr[x][i],val);
}

int query(int x,int y,int val = 0){
	y++;
	for(;x;x -= x & -x)
		for(int i = y;i;i -= i & -i)
			val = max(val,tr[x][i]);
	return val;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,k = in; for(int i = 1;i <= n;i++) h[i] = in,mx = max(mx,h[i]);
	for(int i = 1;i <= n;i++){
		for(int j = k;j >= 0;j--){
			int x = query(h[i] + j,j);
			ans = max(ans,x + 1); add(h[i] + j,j,x + 1);
		}
	}
	printf("%d\n",ans);
	return 0;
}

